package com.fuxi.cloud.desreport.a;

import cn.hutool.core.util.ObjectUtil;
import com.fuxi.cloud.common.constant.CommonConstant;
import com.fuxi.cloud.common.vo.Result;
import com.fuxi.cloud.config.client.JmReportTokenClient;
import com.fuxi.cloud.desreport.entity.JmReportMap;
import com.fuxi.cloud.desreport.model.JmPage;
import com.fuxi.cloud.desreport.service.IJmReportMapService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * b
 *
 * @Author: 扫地僧
 * @CreateTime: 2021-05-03
 */
@RestController("jimuReportMapController")
@RequestMapping({"/jmreport/map"})
public class e {
    private static final Logger a = LoggerFactory.getLogger(e.class);
    @Autowired
    private IJmReportMapService jmReportMapService;
    @Autowired
    private JmReportTokenClient jimuTokenClient;

    public e() {
    }

    @GetMapping({"/mapList"})
    public Result<?> a(HttpServletRequest var1, @RequestParam(name = "label",required = false) String var2, @RequestParam(name = "name",required = false) String var3, @RequestParam(name = "current",defaultValue = "1") Integer var4, @RequestParam(name = "size",defaultValue = "10") Integer var5) {
        String var6 = this.jimuTokenClient.getUsername(var1);
        a.debug("============地图列表查询==========");
        JmReportMap var7 = new JmReportMap();
        var7.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
        var7.setCreateBy(var6);
        if (ObjectUtil.isNotEmpty(var2)) {
            var7.setLabel(var2);
        }

        if (ObjectUtil.isNotEmpty(var3)) {
            var7.setName(var3);
        }

        JmPage var8 = this.jmReportMapService.queryPageList(var7, var4, var5);
        return Result.OK(var8);
    }

    @PostMapping({"/addMapData"})
    public Result<?> a(HttpServletRequest var1, @RequestBody JmReportMap var2) {
        try {
            String var3 = this.jimuTokenClient.getUsername(var1);
            var2.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
            var2.setCreateBy(var3);
            var2.setCreateTime(new Date());
            var2.setUpdateTime(new Date());
            this.jmReportMapService.saveMapSource(var2);
        } catch (Exception var4) {
            return Result.error(403, "操作失败");
        }

        return Result.OK("添加成功！", true);
    }

    @PostMapping({"/delMapSource"})
    public Result<?> b(HttpServletRequest var1, @RequestBody JmReportMap var2) {
        this.jmReportMapService.removeById(var2.getId());
        return Result.OK("删除成功！", true);
    }

    @PostMapping({"/queryMapByCode"})
    public Result<?> c(HttpServletRequest var1, @RequestBody JmReportMap var2) {
        String var3 = this.jimuTokenClient.getUsername(var1);
        a.debug("============地图信息查询==========");
        var2.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
        String var4 = var2.getReportId();
        var2.setCreateBy(var3);
        JmReportMap var5 = this.jmReportMapService.queryMapByCode(var2);
        return Result.OK(var5);
    }
}
